const mysql = require("mysql");

function connectMysql(sql, data) {
    //创建数据库连接
    return new Promise((resolve, rejects) => {
        const connection = mysql.createConnection({
            host: "localhost",
            port: 3306,
            user: "root",
            password: "123456",
            database: "aa_bd"
        })

        //打开连接

        connection.connect();

        connection.query(sql, data, function (error, result) {
            if (error) {
                rejects(error);
            } else {
                resolve(result);
            }


        })

        //关闭连接
        connection.end()

    })
}

module.exports = {
    connectMysql
}
